package com.luych.toolbox.docker.service.sdk.volume;

import com.luych.toolbox.docker.service.sdk.volume.model.DockerVolumesCreateParam;
import com.luych.toolbox.docker.service.sdk.volume.model.DockerVolumesCreateResult;
import com.luych.toolbox.docker.service.sdk.volume.model.DockerVolumesPruneResult;
import com.luych.toolbox.docker.service.sdk.volume.model.DockerVolumesResult;
import org.springframework.web.client.RestTemplate;

public class DockerVolumes {

    private final String url;

    public DockerVolumes(String url) {
        this.url = url;
    }

    public DockerVolume volume(String id) {
        return new DockerVolume(url, id);
    }

    public DockerVolumesResult all() {
        final String uri = url + "/volumes";
        RestTemplate restTemplate = new RestTemplate();
        return restTemplate.getForObject(uri, DockerVolumesResult.class);
    }

    public DockerVolumesCreateResult create(DockerVolumesCreateParam param) {
        final String uri = url + "/volumes/create";
        RestTemplate restTemplate = new RestTemplate();
        return restTemplate.postForObject(uri, param, DockerVolumesCreateResult.class);
    }

    public DockerVolumesPruneResult prune() {
        final String uri = url + "/volumes/prune";
        RestTemplate restTemplate = new RestTemplate();
        return restTemplate.postForObject(uri, null, DockerVolumesPruneResult.class);
    }


}
